package cn.buk.qms.service;

import cn.buk.common.JsonResult;
import cn.buk.common.sc.CommonSearchCriteria;
import cn.buk.tms.sc.SearchUserCriteria;
import cn.buk.tms.common.dto.CustomerDto;
import cn.buk.tms.dto.CustomerDetailDto;
import cn.buk.tms.dto.DtoLoginStatus;
import cn.buk.tms.dto.UserDto;
import cn.buk.tms.sc.SearchCustomerCriteria;
import cn.buk.tms.entity.misc.*;

import java.util.List;
import java.util.Set;

/**
 * @author yfdai
 */
public interface UserService {

  List<User> search(int enterpriseId, SearchUserCriteria sc);

  /**
   * 查找员工用户
   */
  List<UserDto> searchUsers(int enterpriseId, SearchUserCriteria sc);

  /**
   * 查找会员用户
   */
  List<UserDto> searchMembers(int enterpriseId, SearchUserCriteria sc);

  User getUserById(int id);

  User getUserById(int enterpriseId, int id);

  User getUserByUsername(String username);

  /**
   * 根据手机号查找用户信息
   *
   * @param ownerId  应用所属者的id
   * @param mobile   手机号
   * @param userType 用户类型
   */
  User getUserByMobile(final int ownerId, String mobile, int userType);


  int createUser(User user, final int enterpriseId, final String invitationCode);

  int createUserByRoleAdmin(User user, final int enterpriseId, final String invitationCode);

  /**
   * 创建客户(企业信息）
   */
  int createCustomer(final int enterpriseId, final int userId, final String username, Customer c);
  int createOrUpdateCustomer(final int enterpriseId, final int userId, final String username, Customer c);

  /**
   * 修改密码
   */
  JsonResult updateUserPassword(int enterpriseId, int userId, String username, String currentPassword, String newPassword, String confirmPassword);

  JsonResult checkIn(final int ownerId, final int enterpriseId, final int userId, final String ip);

  List<AmountHistory> searchTransactionHistory(int enterpriseId, CommonSearchCriteria sc);


  void createLoginHistory(LoginHistory log);

  List<LoginHistory> searchHistory(int enterpriseId, String username, CommonSearchCriteria sc);

  UserDto searchEnterpriseBalance(int enterpriseId);

  void saveToken(DtoLoginStatus dtoLoginStatus);

  List<CustomerDto> searchCustomers(int enterpriseId, int userId, SearchCustomerCriteria sc);


  /**
   * 查找客户资料
   *
   * @param enterpriseId 企业ID
   * @param sc           查询条件
   */
  List<CustomerDetailDto> searchCustomerDetails(int enterpriseId, int userId, SearchCustomerCriteria sc);

  List<CustomerDetailDto> searchCustomerByCustomerEnterpriseId(int enterpriseId, int customerEnterpriseId);

  /**
   * 获取企业客户信息
   * @param enterpriseId 企业ID
   * @param id 客户id
   */
  CustomerDetailDto getCustomerById(int enterpriseId, int id);

  /**
   * 修改用户资料
   */
  int updateUser(int enterpriseId, int id, String empname, String email, String mobileNo, String etermUsername,
                 String position, Integer[] deptIds, int status);

  JsonResult searchItineraryInfo(int enterpriseId);

  JsonResult buyItinerary(int enterpriseId);

  int updateCustomer(int enterpriseId, int userId, String username, Customer c);

  /**
   * 加载用户角色
   *
   * @param userId user id
   */
  Set<String> loadRolesByUserId(int userId);

  /**
   * 查找当前用户的权限
   */
  List<RolePrivilege> searchPrivileges(int enterpriseId, int userId);

  /**
   * 重置密码
   */
  int resetPassword(int userId, String newPassword);


  List<Enterprise> searchCustomerTodo(int enterpriseId);

  User getUserByWwUserId(int enterpriseId, String userid);

  /**
   * 为新租户注册生成root用户
   */
  JsonResult registerNewTenancyUser(User user, String invitationCode);

  /**
   * 重置用户密码
   */
  JsonResult resetUserPassword(int enterpriseId, String username, int userId, String newPassword);

  int autoCreateUserByOpenId(int ownerId, String openid);

  void sendAlert(int enterpriseId, final String username, String content);

  JsonResult disableUser(int enterpriseId, String username, int userId);

  JsonResult enableUser(int enterpriseId, String username, int userId);

  JsonResult updateUserUsername(int enterpriseId, String username, int userId, String newUsername);

  JsonResult updateUserEtermUsername(int enterpriseId, String username, int userId, String etermUsername);

  JsonResult updateUserEmail(int enterpriseId, String username, int userId, String email);

  JsonResult updateUserMobile(int enterpriseId, String username, int userId, String mobile);

  /**
   * 通过注册的手机号查找登录用户，只查找主管理员（也就是usn == enterpriseId）的
   */
  List<User> searchUsersByMobile(String mobile);

  UserDto searchUser(int enterpriseId, int id);

  void finishTaskCardMessage(int enterpriseId, String wwUserId, String taskId, String eventKey, Long createTime);

  UserDto searchMemberDetail(int enterpriseId, int id);

  /**
   * 将会员账号与微信公众号用户解绑
   */
  JsonResult unbindWeixinUser(int ownerId, int userId, String openId);

  /**
   * 绑定会员账号和微信公众号用户
   */
  JsonResult bindWeixinUser(int ownerId, int userId, String openId);

  List<User> searchUsersByDepartment(int enterpriseId, int deptId, CommonSearchCriteria sc);
}
